package com.example.medicine.Mapper;


import com.example.medicine.Bean.zhongyao;
import com.example.medicine.Bean.zhongyaoWithCompany;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface zhongyaoMapper {
    @Select("SELECT zhongyao.*,yh.company\n" +
            "            FROM zhongyao\n" +
            "            left join(\n" +
            "            select userid,company \n" +
            "            from yonghu\n" +
            "            where userid in (select createuser from zhongyao)) as yh \n" +
            "            on zhongyao.createuser=yh.userid;")
    List<zhongyaoWithCompany> getAll();
    @Select("select * from [zhongyao]")
    List<zhongyao> getzhongyao();


    @Select("select * from [zhongyao] where id=#{id}")
    zhongyao getById(long id);

    @Insert("insert into [zhongyao](yaoming,ladingming,StandardMedicineName,MedicineClassifyName,bieming,chufangming,yaowuleixing,shifoushiyong,chandi,chuchu,paozhi,yaoxiaoleibie,xing,wei,guijing,tupian,duxing,gongneng,zhuzhi,yongfayongliang,shenhe,createtime) " +
            "values(#{yaoming},#{ladingming},#{StandardMedicineName},#{MedicineClassifyName},#{bieming},#{chufangming},#{yaowuleixing},#{shifoushiyong},#{chandi},#{chuchu},#{paozhi},#{yaoxiaoleibie},#{xing},#{wei},#{guijing},#{tupian},#{duxing},#{gongneng},#{zhuzhi},#{yongfayongliang},#{shenhe},GETDATE())")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    void insert(zhongyao zhongyao);

    @Insert("<script>INSERT INTO [zhongyao] (yaoming, ladingming, StandardMedicineName, MedicineClassifyName, bieming, chufangming, yaowuleixing, shifoushiyong, chandi, chuchu, paozhi, yaoxiaoleibie, xing, wei, guijing, duxing, gongneng, zhuzhi, yongfayongliang, shenhe,createtime) VALUES " +
            "<foreach collection='list' item='item' separator=','>" +
            "(#{item.yaoming}, #{item.ladingming}, #{item.StandardMedicineName}, #{item.MedicineClassifyName}, #{item.bieming}, #{item.chufangming}, #{item.yaowuleixing}, #{item.shifoushiyong}, #{item.chandi}, #{item.chuchu}, #{item.paozhi}, #{item.yaoxiaoleibie}, #{item.xing}, #{item.wei}, #{item.guijing}, #{item.duxing}, #{item.gongneng}, #{item.zhuzhi}, #{item.yongfayongliang}, #{item.shenhe},GETDATE())" +
            "</foreach></script>")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void batchInsertZhongyao(@Param("list") List<zhongyao> zhongyaoList);


    @Update("update [zhongyao] set yaoming=#{yaoming}, ladingming=#{ladingming}, StandardMedicineName=#{StandardMedicineName}, MedicineClassifyName=#{MedicineClassifyName}, bieming=#{bieming}, chufangming=#{chufangming}, yaowuleixing=#{yaowuleixing}, shifoushiyong=#{shifoushiyong}, chandi=#{chandi}, chuchu=#{chuchu}, paozhi=#{paozhi}, yaoxiaoleibie=#{yaoxiaoleibie}, xing=#{xing}, wei=#{wei}, guijing=#{guijing},duxing=#{duxing}, gongneng=#{gongneng}, zhuzhi=#{zhuzhi}, yongfayongliang=#{yongfayongliang} where id=#{id}")
    void update(zhongyao zhongyao);

    @Update("update [zhongyao] set shenhe=#{shenhe},shr=#{shr},shsj=GETDATE() where id=#{id}")
    void updateShenhe(zhongyao zhongyao);

    @Update("update [zhongyao] set tupian=#{tupian} where id=#{id}")
    void updateTupian(zhongyao zhongyao);

    @Delete("delete from [zhongyao] where id=#{id}")
    void deleteById(long id);

}
